﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CNotebook;
using CNotebook.Inventory;

namespace NotebookS2
{
    public partial class SEL_LOTNUMBER : DevExpress.XtraBars.Ribbon.RibbonForm
    {
        public SEL_LOTNUMBER()
        {
            InitializeComponent();
        }

        public string ConnectionString { get; set; }

        public string ItemCode { get; set; }
        public string WarehouseCode { get; set; }

        public string SelectedLotNumber { get; set; }
        public DateTime SelectedExpiryDate { get; set; }


        void BindLotNumber()
        {
            StockManager oManager = new StockManager();

            oManager.ConnectionString = this.ConnectionString;
            oManager.Open();

            DataTable dt = oManager.GetLotNumbers(this.ItemCode, this.WarehouseCode);
            oManager.Close();

            gridControl1.DataSource = dt;
            gridControl1.Refresh();
        }

        private void SEL_LOTNUMBER_Load(object sender, EventArgs e)
        {
            BindLotNumber();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnChoose_Click(object sender, EventArgs e)
        {
            int iRowIndex = gridView1.FocusedRowHandle;

            this.SelectedLotNumber = gridView1.GetRowCellValue(iRowIndex, gridView1.Columns["LotNumber"]).ToString();

            if (gridView1.GetRowCellValue(iRowIndex, gridView1.Columns["ExpiryDate"]).ToString() != "")
            {
                this.SelectedExpiryDate = Convert.ToDateTime(gridView1.GetRowCellValue(iRowIndex, gridView1.Columns["ExpiryDate"]).ToString());
            }
            else
            {
                this.SelectedExpiryDate = System.DateTime.Now;
            }

            this.Close();
        }

        private void gridView1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                btnChoose_Click(sender, e);
            }
        }

        private void gridView1_DoubleClick(object sender, EventArgs e)
        {
            btnChoose_Click(sender, e);
        }
    }
}
